'use strict';

module.exports = function countSameElements(collection) {
  let arr = [];
  let obj = {};
  for(let item of collection){
    if(!obj[item[0]]){
      obj[item[0]] = {} ;
      obj[item[0]].name = item[0];
      if(1<item.length){
        obj[item[0]].summary = parseInt(item[2]);
        if(item.length === 5){
          obj[item[0]].summary = parseInt(item.slice(2,4));      
        }
      }
      else{
        obj[item[0]].summary = 1;
      }
    }
    else{
      if(1<item.length){
        if(item.length === 5){
          obj[item[0]].summary += parseInt(item.slice(2,4));      
        }else{
           obj[item[0]].summary += parseInt(item[2]);
        }
      }
      else{
        obj[item[0]].summary += 1;
      }
    }
  } 
  for(let item in obj){
    arr.push(obj[item]);
  }
  return arr;
}
